/* 堆排序 */
#include<bits/stdc++.h>
using namespace std;

void HeapAdjust(int a[],int s,int m){
    int rc = a[s];
    for(int i=s;i<m;i=i*2){
        
        if(i<m&&a[i]<a[i+1]){
            i++;
        }
        if(rc>a[i]){
            break;
        }else{
            a[s] = a[i];
            s = i;
        }
    }
    a[s] = rc;
}

void HeapSort(int a[],int length){
    for(int i=length/2;i>0;i--){
        HeapAdjust(a,1,length);
    }
    for(int i=length;i>0;i--){
        swap(a[i],a[1]);
        printf("%d",a[i]);
        HeapAdjust(a,1,length-1);
    }
}